import serial
import serial.tools.list_ports
from KA3005P import ka3005p
import time

if __name__ == '__main__':
    ports_list = list(serial.tools.list_ports.comports())
    if len(ports_list) <= 0:
        print("无串口设备\n")
    else:
        print("当前所有的串口如下所示：\n")
        for comport in ports_list:
            print(list(comport)[0], list(comport)[1])
    port = input('请输入BAT(供电的模拟电池ASD906)的串口号(例如COM4)：')
    port.upper()
    dc = ka3005p.KA3005P(port)
    dc.set_vset_voltage(1, 5)
    dc.set_iset_current(1, 1)
    dc.turn_on_output()
    time.sleep(0.1)
    voltage = dc.get_output_voltage(1)
    print(float(voltage))
    current = dc.get_output_current(1)
    print(current)